package com.eonmind.vip.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.eonmind.common.contract.data.base.BaseMongoMapper;
import com.eonmind.common.provider.entity.vip.VipManagement;
import com.mongoplus.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class VipManagementMapper extends BaseMongoMapper<VipManagement> {

    /**
      * @Author 逆飞的流星
      * @Description 保存
      * @Date 17:01 2025/5/13
      **/
    public void saveVipManagement(VipManagement vipManagement){

        try {
            save(vipManagement);
        } catch (Exception e) {
           e.printStackTrace();
        }
    }

    /**
      * @Author 逆飞的流星
      * @Description 更新积分
      * @Date 9:36 2025/5/14
      **/
    public void updateVipManagement(VipManagement vipManagement) {
        UpdateWrapper<VipManagement> updateWrapper = createMgoUpdate().eq(VipManagement::getUserId, vipManagement.getUserId())
                .set(ObjectUtil.isNotEmpty(vipManagement.getPackageId()), VipManagement::getPackageId, vipManagement.getPackageId())
                .set(ObjectUtil.isNotEmpty(vipManagement.getUpdateTime()), VipManagement::getUpdateTime, vipManagement.getUpdateTime())
                .inc(ObjectUtil.isNotEmpty(vipManagement.getIntegral()), VipManagement::getIntegral, vipManagement.getIntegral())
                .set(ObjectUtil.isNotEmpty(vipManagement.getValidityPeriod()), VipManagement::getValidityPeriod, vipManagement.getValidityPeriod())
                .set(ObjectUtil.isNotEmpty(vipManagement.getDel()), VipManagement::getDel, vipManagement.getDel());

        Boolean update = update(updateWrapper);
        System.out.println(update);
    }


}
